package com.ilovepostcard.controller.server;

import java.io.File;


/**
 * generate fake data for testing
 * @author jerry
 *
 */
public class TestServer extends PostcardServer {

    @Override
    public PostcardResult login(String uname, String pwd) {
//        User user = TestUtil.getTestUser();
//        boolean pass = false;
//        if (user.Username.equals(uname) && user.password.equals(pwd)) {
//            pass = true;
//        }
//        String json = pass ? TestUtil.JSON_login_success() : TestUtil.JSON_login_fail();
//        return PostcardResult.parserResult(json);
        return new PostcardServer().login(uname, pwd);
    }

    @Override
    public PostcardResult register(String uname, String pwd, String nickname) {
//        User user = TestUtil.getTestUser();
//        boolean pass = false;
//        if (user.Username.equals(uname) && user.password.equals(pwd)) {
//            pass = true;
//        }
//        String json = pass ? TestUtil.JSON_register_success() : TestUtil.JSON_register_fail();
//        return PostcardResult.parserResult(json);
        return new PostcardServer().register(uname, pwd, nickname);
    }

    @Override
    public PostcardResult userLoginFromOpen(String uname, String nickname,
            int type) {
//        return PostcardResult.parserResult(TestUtil.JSON_login_success());
        return new PostcardServer().userLoginFromOpen(uname, nickname, type);
    }

    @Override
    public PostcardResult getUserInfo(String uname, long uid) {
//        try {
//            Thread.sleep(1000);
//        } catch (InterruptedException e) {
//            e.printStackTrace();
//        }
//        int random = TestUtil.randomInt(10);
//        boolean fail = (random == 1); /* 33% rate to fail */
//        String json = fail ? TestUtil.JSON_getuserinfo_fail() : TestUtil.JSON_getuserinfo_success();
//        return PostcardResult.parserResult(json);
        return new PostcardServer().getUserInfo(uname, uid);
    }
    
    

    @Override
    public PostcardResult getRecommendPostcard(long uid, int pi, int pc) {
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        return randomPostcardResult();
    }

    @Override
    public PostcardResult getFriendPostcard(long uid, int pi, int pc) {
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        return randomPostcardResult();
    }

    @Override
    public PostcardResult getMyPostcard(long uid, int pi, int pc) {
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        return randomPostcardResult();
    }
    
    @Override
    public PostcardResult searchPostcard(String keyword, int pi, int pc) {

        return null;
    }

    @Override
    public PostcardResult updateUserInfo(long uid, int sex, String birthday, String province, String city,
            String introduction, String nickname) {
        return new PostcardServer().updateUserInfo(uid, sex, birthday, province, city, introduction, nickname);
    }

    private PostcardResult randomPostcardResult() {
        int random = TestUtil.randomInt(6);
        boolean fail = (random == 1); /* 33% rate to fail */
        String json = fail ? TestUtil.JSON_getPostcard_fail() : TestUtil.JSON_getPostcard_success();
        return PostcardResult.parserResult(json);
    }

    @Override
    public PostcardResult getUploadSKey() {
        return new PostcardServer().getUploadSKey();
    }

    @Override
    public PostcardResult uploadFile(int type, String fileName, String skey,
            long uid, int x, int y, int w, int h, int r, File source) {
        return new PostcardServer().uploadFile(type, fileName, skey, uid, x, y, w, h, r, source);
    }

    @Override
    public PostcardResult canModifyNickname(long uid) {
        return new PostcardServer().canModifyNickname(uid);
    }
    
    @Override
    public PostcardResult listCity() {
        return new PostcardServer().listCity();
    }
    
    @Override
    public PostcardResult createPostcard(long uid, String location,
            String tofriendswords, String story, boolean isshowwords,
            double latitude, double longitude, String skey, int viewPermission,
            int locationPermission, String tags) {
        return new PostcardServer().createPostcard(uid, location, tofriendswords, story, isshowwords, latitude, longitude, skey, viewPermission, locationPermission, tags);
    }
    
    @Override
    public PostcardResult deletePostcard(long pid, long uid) {
        return null;
    }
    
    @Override
    public PostcardResult postProposal(long uid, String body) {
        return null;
    }
    
    @Override
    public PostcardResult checkNew(String ver, String channel) {
        return null;
    }

    @Override
    public PostcardResult attention(long uidMy, long uidOther, int type) {
        return null;
    }

    @Override
    public PostcardResult checkAttention(long uidMy, long uidOther) {
        return null;
    }

    @Override
    public PostcardResult getAttentionList(long uid, int type, int pi, int pc) {
        return null;
    }

    @Override
    public PostcardResult getUserActiveTime(long uid) {
        return null;
    }

    @Override
    public PostcardResult likePostcard(long uid, long pid) {
        return null;
    }

    @Override
    public PostcardResult newPostcardComment(long uid, long pid, String body) {
        return null;
    }

    @Override
    public PostcardResult getPostcardComments(long pid, int pi, int pc) {
        return null;
    }

    @Override
    public PostcardResult searchUser(String k, int pi, int pc) {
        return null;
    }

    @Override
    public PostcardResult getNewMessageCount(long uid) {
        return null;
    }

    @Override
    public PostcardResult deleteMessage(long uid, long mid) {
        return null;
    }

    @Override
    public PostcardResult listMessage(long uid, int pi, int pc) {
        return null;
    }

    @Override
    public PostcardResult getUserHeadImg(long uid) {
        return null;
    }

    @Override
    public PostcardResult listAddress(long uid, int pi, int pc) {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public PostcardResult newAddress(long uid, String name, String telephone,
            String province, String city, String address, String zipcode) {
        // TODO Auto-generated method stub
        return null;
    }
    
    
}
